<template>
    <div>
        <input type="text" placeholder="请输入手机号" v-model="phone">
        <input type="text" placeholder="请输入密码" v-model="password">
        <button @click="registry">注册</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return {
            phone:'',
            password:''
        }
    },
    methods:{
        //注册
        registry(){
            if(/^\d{11}$/.test(this.phone) && /^[0-9a-zA-Z]{6,20}$/.test(this.password)){
                axios.post('/api/registry',{phone:this.phone,password:this.password}).then(res => {
                    console.log(res);
                    if(res.data.code === 1){
                        alert("注册成功");
                        this.$router.push('/login');
                    }
                })
            }else{
                alert("参数有误")
            }
        }
    }
}
</script>